
package com.bluelinelabs.conductor.demo.changehandler;

import ohos.agp.animation.AnimatorGroup;
import ohos.agp.animation.AnimatorProperty;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;

import com.bluelinelabs.conductor.conductor.changehandler.AnimatorChangeHandler;

/**
 * lipeiquan
 *
 * @since 2021-05-06
 */
public class FlipChangeHandler extends AnimatorChangeHandler {

    private static final long DEFAULT_ANIMATION_DURATION = 300;

    public enum FlipDirection {
        LEFT(-180, 180, Component.AXIS_Y),
        RIGHT(180, -180, Component.AXIS_Y),
        UP(-180, 180, Component.AXIS_X),
        DOWN(180, -180, Component.AXIS_X);

        final int inStartRotation;
        final int outEndRotation;
        final int property;

        FlipDirection(int inStartRotation, int outEndRotation, int property) {
            this.inStartRotation = inStartRotation;
            this.outEndRotation = outEndRotation;
            this.property = property;
        }
    }

    private final long animationDuration;
    private final FlipDirection flipDirection;

    public FlipChangeHandler() {
        this(FlipDirection.RIGHT);
    }

    public FlipChangeHandler(FlipDirection flipDirection) {
        this(flipDirection, DEFAULT_ANIMATION_DURATION);
    }

    public FlipChangeHandler(long animationDuration) {
        this(FlipDirection.RIGHT, animationDuration);
    }

    public FlipChangeHandler(FlipDirection flipDirection, long animationDuration) {
        this.flipDirection = flipDirection;
        this.animationDuration = animationDuration;
    }


    @Override
    protected AnimatorGroup getAnimator(ComponentContainer container, Component from, Component to, boolean isPush, boolean toAddedToContainer) {
        AnimatorGroup animatorGroup = new AnimatorGroup();
        AnimatorProperty fromAnimatorProperty = null;
        AnimatorProperty toAnimatorProperty = null;

        if (to != null) {
            toAnimatorProperty = to.createAnimatorProperty();
            if (flipDirection.property == Component.AXIS_Y) {


            } else {

            }

        } else if (from != null) {
            fromAnimatorProperty = from.createAnimatorProperty();
            if (flipDirection.property == Component.AXIS_Y) {


            } else {

            }
        }

        if (fromAnimatorProperty != null && toAnimatorProperty != null) {
            animatorGroup.runParallel(fromAnimatorProperty, toAnimatorProperty);
        } else if (fromAnimatorProperty != null) {
            animatorGroup.runParallel(fromAnimatorProperty);
        } else if (toAnimatorProperty != null) {
            animatorGroup.runParallel(toAnimatorProperty);
        }

        return animatorGroup;
    }

    @Override
    protected void resetFromView(Component from) {

    }
}
